export const setStorage = (key, value) => {
  try {
    wx.setStorageSync(key, value)
  } catch (error) {
    console.error(`存储${key}时出现错误`)
  }
}

export const getStorage = (key) => {
  try {
    return wx.getStorageSync(key)
  } catch (error) {
    console.error(`获取${key}时出现错误`)
  }
}

export const removeStorage = (key) => {
  try {
    wx.removeStorageSync(key)
  } catch (error) {
    console.error(`移除${key}时出现错误`)
  }
}

export const clearStorage = (key) => {
  try {
    wx.clearStorageSync()
  } catch (error) {
    console.error(`移除时出现错误`)
  }
}

export const asyncSetStorage = (key, data) => {
  return new Promise((resolve) => {
    wx.setStorage({
      key,
      data,
      complete: (res) => {
        resolve(res)
      }
    })
  })
}

export const asyncGetStorage = (key) => {
  return new Promise((resolve) => {
    wx.getStorage({
      key,
      complete: (res) => {
        resolve(res)
      }
    })
  })
}

export const asyncRemoveStorage = (key) => {
  return new Promise((resolve) => {
    wx.removeStorage({
      key: key,
      complete: (res) => {
        resolve(res)
      }
    })
  })
}

export const asyncClearStorage = () => {
  return new Promise((resolve) => {
    wx.clearStorage({
      complete: (res) => {
        resolve(res)
      }
    })
  })
}
